﻿@using HouseHoldBudget.App_GlobalResources
@using HouseHoldBudget.Models.Incomes
@using Kendo.Mvc.UI
@model HouseHoldBudget.Models.Expenses.ExpensesListModel
@{
    ViewBag.Title = "Gérer mes revenus";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm())
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Content/images/incomes.png")" alt="" />
            @CustomResources.ManageMyFixedIncomes_Title
        </div>
    </div>
    <p>
    </p>
    <table class="content">
        <tr>
            <td>
                @(Html.Kendo().Grid<FixedIncomeModel>()
                    .Name("incomes-grid")
                    .Columns(columns =>
                                {
                                    columns.Command(commands =>
                                                        {
                                                            commands.Edit();
                                                            commands.Destroy();
                                                        }).Width(250);
                                    columns.Bound(x => x.FixedIncomesOn).Format("{0:d}").Width(150)
                                        .Title(@CustomResources.Common_Date);
                                    columns.Bound(x => x.FixedIncomesName)
                                        .Title(@CustomResources.Common_Label);
                                    columns.Bound(x => x.FixedIncomesAmount)
                                        .Title(@CustomResources.Common_Amount)
                                        .Format("{0:C}");
                                })
                    .ToolBar(toolbar => toolbar.Create().Text("Ajouter une dépense"))
                    .Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
                    .DataSource(dataBinding => dataBinding.Ajax()
                                        .Model(model =>
                                                   {
                                                       model.Id(p => p.Id);
                                                       model.Field(p => p.FixedIncomesOn);
                                                       model.Field(p => p.FixedIncomesName);
                                                       model.Field(p => p.FixedIncomesAmount);
                                                   })
                                        .Read(read => read.Action("GetFixedIncomesList", "Incomes"))
                                        .Create(create => create.Action("InsertFixedIncome", "Incomes"))
                                        .Update(update => update.Action("UpdateFixedIncome", "Incomes"))
                                        .Destroy(destroy => destroy.Action("DeleteFixedIncome", "Incomes"))
                                        .Aggregates(agg => agg.Add(o => o.FixedIncomesAmount).Sum())
                                        .PageSize(20))

                    .Groupable()
                    .Scrollable()
                    .Sortable()
                    .Filterable())                
            </td>
        </tr>
    </table>
}